package com.assignwork.modules.corp;

import com.assignwork.dto.CorpMachineSearchDTO;
import com.assignwork.dto.CorpMachineSubmitDTO;
import com.assignwork.service.ICorpMachineService;
import com.assignwork.vo.CorpMachineListVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.common.cache.CacheNames;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.cache.utils.CacheUtil;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName CorpMachineController
 * @Description 单位机械前端控制器
 * @Author dujianyu
 * @Date 2023/12/8 9:54
 */
@RestController
@AllArgsConstructor
@RequestMapping("corp/corpMachine")
public class CorpMachineController extends BladeController {

    private ICorpMachineService service;

    @GetMapping("/page")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "分页", notes = "传入dto")
    public R<IPage<CorpMachineListVO>> page(CorpMachineSearchDTO dto, Query query) {
        return R.data(service.selectCorpMachinePage(dto, Condition.getPage(query)));
    }

    @GetMapping("/list")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "列表", notes = "传入dto")
    @Cacheable(value = CacheNames.ALL_CORP_MACHINE, key="#dto.teamId")
    public R<List<CorpMachineListVO>> list(CorpMachineSearchDTO dto) {
        return R.data(service.selectCorpMachineList(dto));
    }

    @GetMapping("list-fixed-machine")
    public R listFixedMachine(CorpMachineSearchDTO dto) {
        return R.data(service.listFixedMachine(dto));
    }

    @PostMapping("submit")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "新增或修改", notes = "传入dto")
    @CacheEvict(value = CacheNames.ALL_CORP_MACHINE, allEntries = true)
    public R<Boolean> submitFixedMachine(@RequestBody CorpMachineSubmitDTO dto) {
        return R.status(service.submitCorpMachine(dto));
    }

    @PostMapping("/remove")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "删除", notes = "传入id")
    @CacheEvict(value = CacheNames.ALL_CORP_MACHINE, allEntries = true)
    public R<Boolean> remove(@ApiParam(value = "主键集合", required = true) @RequestParam String id) {
        return R.status(service.deleteLogic(Func.toLongList(id)));
    }

}
